﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using stefab;
using stefab.Musique;
using System.Net;
using System.IO;

namespace projet1_stefab
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            cbCategorie.SelectedIndex = 0;
            this.AcceptButton = btnSearchArtist;
        }

        private void btnSearchArtist_Click(object sender, EventArgs e)
        {
            if (cbCategorie.SelectedIndex == 0)
            {
                tabResultat.SelectedTab = tabPageArtist;

                List<Event> lesEvents = LastFmApi.getArtistEvents(txtRecherche.Text);

                lstEvent.Items.Clear();
                lstEvent.DisplayMember = "title";
                //On ajoute les évenements à la listbox
                foreach (Event unEvent in lesEvents)
                {
                    lstEvent.Items.Add(unEvent);
                }

            }
            else if (cbCategorie.SelectedIndex == 1)
            {
                tabResultat.SelectedTab = tabPageLieu;

                List<Event> lesEvents = LastFmApi.getGeoEvents(txtRecherche.Text);

                lstEventLieu.Items.Clear();
                lstEventLieu.DisplayMember = "title";

                foreach (Event unEvent in lesEvents)
                {
                    lstEventLieu.Items.Add(unEvent);
                }
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void tpEvent_Click(object sender, EventArgs e)
        {

        }

        private void lstEvent_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnPlus2.Visible = true;
            Event unEvent = (Event)lstEvent.SelectedItem; //On caste toujours avec une classe
            lblId.Text = "N° évènement : " + unEvent.id;
            lblTitre.Text = "Titre : " + unEvent.title;
            lblDate.Text = "Date : " + unEvent.date;
            lblUrlContent.Text = unEvent.linkSite;
            lblDescription.Text = "Description : " + unEvent.description;
            picEvent.ImageLocation = unEvent.linkImage;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(lblUrlContent.Text);  
        }

        private void txtRecherche_KeyPress(object sender, KeyPressEventArgs e)
        {
          
        }

        private void lstEventLieu_SelectedIndexChanged(object sender, EventArgs e)
        {
            btnPlus.Visible = true;
            Event unEvent = (Event)lstEventLieu.SelectedItem;
            lblidEvent.Text = "N° évènement : " + unEvent.id;
            lblTitreEvent.Text = "Titre : " + unEvent.title;
            lblDateEvent.Text = "Date : " + unEvent.date;
            lblUrlEvent.Text = unEvent.linkSite;
            lblDescriptionEvent.Text = "Description : " + unEvent.description;
            picEvent2.ImageLocation = unEvent.linkImage;
        }

        private void btnPlus_Click(object sender, EventArgs e)
        {
            Event unEvent = (Event)lstEventLieu.SelectedItem;
            DetailEvent detailsForm = new DetailEvent(unEvent);
            detailsForm.Show();
        }

        private void btnPlus2_Click(object sender, EventArgs e)
        {
            Event unEvent = (Event)lstEvent.SelectedItem;
            DetailEvent detailsForm = new DetailEvent(unEvent);
            detailsForm.Show();
        }
    }
}
